// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-18

package responses

import (
	"gitee.com/go-libs/db-xorm/db"
	"server/app/http/models"
	"server/app/kind"
	"server/app/lib"
	"server/app/lib/encryption"
)

// QrcodeResponse
// 二维码结果.
type QrcodeResponse struct {
	Id           int64
	Timeout      kind.QrcodeTimeout
	ScannedCount int
	ScannedLimit kind.QrcodeLimit
	AppliedAt    db.Datetime
	AppliedCount int
	Params       string
	CreatedAt    db.Datetime

	// Encryption
	// 加密数据.
	Encryption encryption.Encryption
	Path       string
}

// With
// 绑定数据.
func (o *QrcodeResponse) With(m *models.Qrcode) *QrcodeResponse {
	o.Id = m.Id
	o.Timeout = m.Timeout
	o.ScannedCount = m.ScannedCount
	o.ScannedLimit = m.ScannedLimit
	o.AppliedAt = m.AppliedAt
	o.AppliedCount = m.AppliedCount
	o.CreatedAt = m.CreatedAt
	o.Params = m.Params

	o.Encryption = lib.Encryption.EncodeQrcode(m.Id, m.Sign)
	o.Path = m.Type.BuildPath()
	return o
}
